import logging

from django.contrib.auth import get_user_model

from apps.account.serializers import UserSerializer

User = get_user_model()


def jwt_response_payload_error_handler(serializer, request=None):
    # print("JWT: serializer=%s", serializer)
    return {
        'status': False,
        'message': "login failed",
        'detail': serializer.errors
    }


def jwt_response_payload_handler(token, user=None, request=None):
    # print("JWT: token=%s", token, user)
    key = 'user'

    value = UserSerializer(user, context={'request': request}).data
    return {
        'status': True,
        'token': token,
        key: value
    }
